home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Draw Editor / Source / ShapeCommands.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-11  |  14.8 KB  |  573 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ShapeCommands.h
  3.  
  4.     Contains:    Shape command Classes Definition
  5.  
  6.     Written by:    Dave Stafford
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. #ifndef _SHAPECOMMANDS_
  12. #define _SHAPECOMMANDS_
  13.  
  14. // -- DrawEditor Includes --
  15.  
  16. #ifndef _COMPILERDEFS_
  17. #include "CompDefs.h"
  18. #endif
  19.  
  20. #ifndef _DRAWEDITORCONSTANTS_
  21. #include "DrawEditorConstants.h"
  22. #endif
  23.  
  24. #ifndef _COMMAND_
  25. #include "Command.h"
  26. #endif
  27.  
  28. #ifndef _DRAWEDITORDEF_
  29. #include "DrawEditorDef.h"
  30. #endif
  31.  
  32. #ifndef _PALETTE_
  33. #include "Palette.h"
  34. #endif
  35.  
  36. //=============================================================================
  37. // Constants
  38. //=============================================================================
  39. const ODPropertyName     kPropFrameInfo = "SampleCode:Property:FrameInfo";
  40. const ODPropertyName     kPropMouseDownOffset = "SampleCode:Property:MouseDownLoc";
  41. const ODValueType         kODPointValue = "Sample:ValueType:ODPoint";
  42.  
  43.  
  44. //=============================================================================
  45. // Forward Declarations
  46. //=============================================================================
  47. class DrawEditor;
  48. class CShape;
  49. class ODFacet;
  50. class CSelection;
  51. class COrderedList;
  52. class ODDragItemIterator;
  53. class CSubscribeLink;
  54. class CPublishLink;
  55.  
  56. //=============================================================================
  57. // CModifySelectionCommand
  58. //=============================================================================
  59. class CModifySelectionCommand : public CCommand
  60. {
  61. public:
  62.     // -- Init --
  63.     CModifySelectionCommand(DrawEditor* theEditor,
  64.                             CSelection* selection,
  65.                             ODBoolean canUndo = kODFalse,
  66.                             ODBoolean changesContent = kODFalse,
  67.                             ODID undoTextIndex = kUndoCommandIndex,
  68.                             ODID redoTextIndex = kRedoCommandIndex);
  69.     
  70.     virtual ~CModifySelectionCommand();
  71.     
  72.     // -- Inherited API --
  73.     virtual void CaptureCommandState(Environment* ev);
  74.     virtual void UndoCommand(Environment* ev);
  75.     virtual    void RedoCommand(Environment* ev);
  76.     
  77.     // -- New API --
  78.             void SelectModifiedShapes(Environment* ev);
  79. public:
  80.  
  81.     CSelection*        fSelection;
  82.     COrderedList*    fSubscribeLinks;
  83.     COrderedList*    fSavedShapes;
  84. };
  85.  
  86.  
  87. //=============================================================================
  88. // CResizeSelectionCommand
  89. //=============================================================================
  90. class CResizeSelectionCommand : public CModifySelectionCommand
  91. {
  92. public:
  93.     
  94.     // -- Init --
  95.     CResizeSelectionCommand(DrawEditor* theEditor,
  96.                             ODFacet* sourceFacet,
  97.                             CSelection* selection,
  98.                             Rect& baseRect,
  99.                             Rect& resizeRect);
  100.     
  101.     virtual ~CResizeSelectionCommand();
  102.  
  103. public:
  104.     
  105.     // Undo-able commands
  106.     // Should call inherited in derivative classes
  107.     virtual void UndoCommand(Environment* ev);
  108.     virtual void RedoCommand(Environment* ev);
  109.     
  110.     // Is called from DoCommand. Used to store information
  111.     // about the command ( shapelists, etc. ).
  112.     virtual void CaptureCommandState(Environment* ev);
  113.     
  114.     // Called just before the command is deleted.
  115.     // Default does nothing
  116.     virtual void Commit(Environment* ev, ODDoneState state);
  117.     
  118.     // -- Must Override this method --
  119.     // This method should only be called once per instance
  120.     // Should call inherited in derivative classes
  121.     virtual void DoCommand(Environment* ev);
  122.     
  123.  
  124. //----------------------------------------------------------------------------------------
  125. // Data Members
  126. //
  127. private:
  128.     Rect                fBaseRect;
  129.     Rect                fResizeRect;
  130.  
  131.     ODFacet*            fSourceFacet;
  132. };
  133.  
  134.  
  135.  
  136.  
  137. //=============================================================================
  138. // CNewShapeCommand
  139. //=============================================================================
  140. class CNewShapeCommand : public CCommand
  141. {
  142. public:
  143.     
  144.     // -- Init --
  145.     CNewShapeCommand(DrawEditor* theEditor,
  146.                         ODFacet* sourceFacet,
  147.                         Rect& bounds,
  148.                         CRGBColor& color,
  149.                         ODSShort shapeType,
  150.                         CSelection* selection);
  151.     
  152.     virtual ~CNewShapeCommand();
  153.  
  154. public:
  155.     
  156.     // Undo-able commands
  157.     // Should call inherited in derivative classes
  158.     virtual void UndoCommand(Environment* ev);
  159.     virtual void RedoCommand(Environment* ev);
  160.     
  161.     // Is called from DoCommand. Used to store information
  162.     // about the command ( shapelists, etc. ).
  163.     virtual void CaptureCommandState(Environment* ev);
  164.     
  165.     // Called just before the command is deleted.
  166.     // Default does nothing
  167.     virtual void Commit(Environment* ev, ODDoneState state);
  168.     
  169.     // -- Must Override this method --
  170.     // This method should only be called once per instance
  171.     // Should call inherited in derivative classes
  172.     virtual void DoCommand(Environment* ev);
  173.     
  174.  
  175. //----------------------------------------------------------------------------------------
  176. // Data Members
  177. //
  178. private:
  179.     CRGBColor    fShapeColor;
  180.     ODSShort    fShapeType;
  181.     Rect        fShapeBounds;
  182.     CShape*        fShape;
  183.     CSelection*    fSelection;
  184.     ODFacet*    fSourceFacet;
  185. };
  186.  
  187.  
  188. //=============================================================================
  189. // CMoveShapeCommand
  190. //
  191. // The move shape command actually handles the 4 shape move
  192. // commands: MoveForward, MoveFront, MoveBackward, and MoveBack
  193. //=============================================================================
  194. class CMoveShapeCommand : public CCommand
  195. {
  196. public:
  197.     
  198.     // -- Init --
  199.     CMoveShapeCommand(DrawEditor* theEditor,
  200.                         ODFrame* sourceFrame,
  201.                         ODCommandID moveType,
  202.                         CSelection* selection);
  203.     
  204.     virtual ~CMoveShapeCommand();
  205.  
  206. public:
  207.     
  208.     // Undo-able commands
  209.     // Should call inherited in derivative classes
  210.     virtual void UndoCommand(Environment* ev);
  211.     virtual void RedoCommand(Environment* ev);
  212.     
  213.     // Is called from DoCommand. Used to store information
  214.     // about the command ( shapelists, etc. ).
  215.     virtual void CaptureCommandState(Environment* ev);
  216.     
  217.     // Called just before the command is deleted.
  218.     // Default does nothing
  219.     virtual void Commit(Environment* ev, ODDoneState state);
  220.     
  221.     // -- Must Override this method --
  222.     // This method should only be called once per instance
  223.     // Should call inherited in derivative classes
  224.     virtual void DoCommand(Environment* ev);
  225.     
  226.     // New API
  227.     void MoveShape(Environment* ev, CShape* moveShape, CShape* shape);
  228.     CShape* FindReferenceShape(Environment* ev, CShape* moveShape);
  229.  
  230. //----------------------------------------------------------------------------------------
  231. // Data Members
  232. //
  233. private:
  234.     ODCommandID        fMoveType;
  235.     ODFrame*        fSourceFrame;
  236.     CSelection*        fSelection;
  237.     COrderedList*    fSavedShapes;
  238. };
  239.  
  240.  
  241. //=============================================================================
  242. // CColorSelectionCommand
  243. //=============================================================================
  244. class CColorSelectionCommand : public CCommand
  245. {
  246. public:
  247.     
  248.     // -- Init --
  249.     CColorSelectionCommand(DrawEditor* theEditor,
  250.                             CSelection* selection,
  251.                             CRGBColor& newColor);
  252.     
  253.     virtual ~CColorSelectionCommand();
  254.  
  255. public:
  256.     
  257.     // Undo-able commands
  258.     // Should call inherited in derivative classes
  259.     virtual void UndoCommand(Environment* ev);
  260.     virtual void RedoCommand(Environment* ev);
  261.     
  262.     // Is called from DoCommand. Used to store information
  263.     // about the command ( shapelists, etc. ).
  264.     virtual void CaptureCommandState(Environment* ev);
  265.     
  266.     // Called just before the command is deleted.
  267.     // Default does nothing
  268.     virtual void Commit(Environment* ev, ODDoneState state);
  269.     
  270.     // -- Must Override this method --
  271.     // This method should only be called once per instance
  272.     // Should call inherited in derivative classes
  273.     virtual void DoCommand(Environment* ev);
  274.     
  275.  
  276. //----------------------------------------------------------------------------------------
  277. // Data Members
  278. //
  279. private:
  280.     CRGBColor            fColor;
  281.  
  282.     COrderedList*        fSavedColors;
  283.     CSelection*            fSelection;
  284. };
  285.  
  286.  
  287.  
  288. //=============================================================================
  289. // CDragShapeCommand
  290. //=============================================================================
  291. class CDragShapeCommand : public CCommand
  292. {
  293. public:
  294.     
  295.     // -- Init --
  296.     CDragShapeCommand(DrawEditor* theEditor,
  297.                     ODFacet* sourceFacet,
  298.                     CSelection* selection,
  299.                     ODEventData* event,
  300.                     ODBoolean showFeedBack,
  301.                     ODBoolean canUndo = kODTrue);
  302.     
  303.     virtual ~CDragShapeCommand();
  304.  
  305. public:
  306.     
  307.     // Undo-able commands
  308.     // Should call inherited in derivative classes
  309.     virtual void UndoCommand(Environment* ev);
  310.     virtual void RedoCommand(Environment* ev);
  311.     
  312.     // Is called from DoCommand. Used to store information
  313.     // about the command ( shapelists, etc. ).
  314.     virtual void CaptureCommandState(Environment* ev);
  315.     
  316.     // Called just before the command is deleted.
  317.     // Default does nothing
  318.     virtual void Commit(Environment* ev, ODDoneState state);
  319.     
  320.     // -- Must Override this method --
  321.     // This method should only be called once per instance
  322.     // Should call inherited in derivative classes
  323.     virtual void DoCommand(Environment* ev);
  324.     
  325.     // New API ( Drag Stuff )
  326.     ODBoolean    Drag(Environment* ev, ODEventData* event);
  327.     void         DragCompleted(Environment* ev);
  328.     ODShape*     CreateDragShape(Environment* ev, ODFacet* facet);
  329.     void         SelectDraggedShapes(Environment* ev);
  330.     void         CreateLink(Environment* ev, CPublishLink* pLink);
  331.  
  332.     
  333.  
  334. //----------------------------------------------------------------------------------------
  335. // Data Members
  336. //
  337. private:
  338.  
  339.     ODEventData*        fEventData;
  340.     ODBoolean            fShowDragFeedback;
  341.     CSelection*            fSelection;
  342.     COrderedList*        fSavedShapes;
  343.     COrderedList*        fPublishLinks;
  344.     COrderedList*        fSubscribeLinks;
  345.     
  346.     ODRgnHandle            fDragRegion;
  347.     ODDragResult        fDragResult;
  348.     ODFacet*            fSourceFacet;
  349.     
  350.     ODPart*                fDestinationPart;
  351.     CPublishLink*        fPublishLink;
  352.     
  353.     ODBoolean            fTransactionClosed;
  354. };
  355.  
  356.  
  357. //=============================================================================
  358. // CDropShapeCommand
  359. //=============================================================================
  360. class CDropShapeCommand : public CCommand
  361. {
  362. public:
  363.     // -- Init --
  364.     CDropShapeCommand(DrawEditor* theEditor,
  365.                     ODFacet* sourceFacet,
  366.                     ODDragItemIterator* dropInfo,
  367.                     CSelection* selection,
  368.                     ODPoint& dropPoint,
  369.                     ODBoolean canUndo = kODTrue);
  370.     
  371.     virtual ~CDropShapeCommand();
  372.     
  373.     // -- Accessors --
  374.     ODDropResult GetDropResult();
  375.     
  376.     // Undo-able commands
  377.     // Should call inherited in derivative classes
  378.     virtual void UndoCommand(Environment* ev);
  379.     virtual void RedoCommand(Environment* ev);
  380.     
  381.     // Is called from DoCommand. Used to store information
  382.     // about the command ( shapelists, etc. ).
  383.     virtual void CaptureCommandState(Environment* ev);
  384.     
  385.     // Called just before the command is deleted.
  386.     // Default does nothing
  387.     virtual void Commit(Environment* ev, ODDoneState state);
  388.     
  389.     // -- Must Override this method --
  390.     // This method should only be called once per instance
  391.     // Should call inherited in derivative classes
  392.     virtual void DoCommand(Environment* ev);
  393.  
  394.     // -- New API ( Drop Stuff ) --
  395.     
  396.     // Check the drop result, and cancel Undo if the drop failed.
  397.     void AdjustUndo(Environment* ev);
  398.  
  399.     // Return non-zero value if the source part was moved;
  400.     void GetDropOrigin(Environment* ev, ODPoint* originPoint);
  401.  
  402.     // Drop methods
  403.     virtual void ExecuteDrop(Environment* ev);
  404.  
  405.     ODBoolean DoDroppedInSameFrame(Environment* ev, 
  406.                             ODStorageUnit* dropSU, 
  407.                             ODPoint& mouseOffset, 
  408.                             ODPoint& dropPoint);
  409.  
  410.     void SelectDroppedShapes(Environment* ev);
  411.  
  412.  
  413. protected:
  414.     CSelection*            fSelection;
  415.     ODFacet*            fSourceFacet;
  416.  
  417.     ODDropResult        fDropResult;
  418.     ODBoolean            fDroppedInSameFrame;
  419.     ODDragItemIterator* fDropInfo;
  420.     
  421.     ODPoint                fDropPoint;
  422.     ODPoint                fDropOffset;
  423.     
  424.     COrderedList*    fSavedShapes;
  425.     COrderedList*    fPublishLinks;
  426.     COrderedList*    fSubscribeLinks;
  427.     
  428. };
  429.  
  430.  
  431. //=============================================================================
  432. // CDropAsCommand
  433. //=============================================================================
  434. class CDropAsCommand : public CDropShapeCommand
  435. {
  436. public:
  437.     // -- Init --
  438.     CDropAsCommand(DrawEditor* theEditor,
  439.                     ODFacet* sourceFacet,
  440.                     ODDragItemIterator* dropInfo,
  441.                     CSelection* selection,
  442.                     ODPoint& dropPoint,
  443.                     ODBoolean doEmbed);
  444.     
  445.     virtual ~CDropAsCommand();
  446.     
  447.     // Drop methods
  448.     void ExecuteDrop(Environment* ev);
  449.  
  450.  
  451. private:
  452.     // True for embed, false for merge
  453.     ODBoolean            fDoEmbed;
  454.     
  455. };
  456.  
  457.  
  458. //=============================================================================
  459. // CCutCopyClearShapeCommand
  460. //=============================================================================
  461. class CCutCopyClearShapeCommand : public CCommand
  462. {
  463. public:
  464.     
  465.     // -- Init --
  466.     CCutCopyClearShapeCommand(DrawEditor* theEditor,
  467.                     ODFrame* sourceFrame,
  468.                     CSelection* selection,
  469.                     ODCommandID command);
  470.     
  471.     virtual ~CCutCopyClearShapeCommand();
  472.  
  473. public:
  474.     
  475.     // Inherited API
  476.     virtual void UndoCommand(Environment* ev);
  477.     virtual void RedoCommand(Environment* ev);
  478.     virtual void CaptureCommandState(Environment* ev);
  479.     virtual void Commit(Environment* ev, ODDoneState state);
  480.     virtual void DoCommand(Environment* ev);
  481.     
  482.     // New API ( Cut / Copy Stuff )
  483.     void         SelectCutShapes(Environment* ev);
  484.     void        WriteShapesToClipboard(Environment* ev);
  485.     
  486.  
  487. //----------------------------------------------------------------------------------------
  488. // Data Members
  489. //
  490. private:
  491.  
  492.     ODFrame*            fSourceFrame;
  493.     CSelection*            fSelection;
  494.     
  495.     ODCloneKind            fCloneKind;
  496.     ODUpdateID            fUpdateID;
  497.     ODCommandID            fCommandID;
  498.     COrderedList*        fSavedShapes;
  499.     COrderedList*         fPublishLinks;
  500.     COrderedList*        fSubscribeLinks;
  501.     
  502. };
  503.  
  504.  
  505. //=============================================================================
  506. // CPasteCommand
  507. //=============================================================================
  508. class CPasteCommand : public CCommand
  509. {
  510. public:
  511.     // -- Init --
  512.     CPasteCommand(DrawEditor* theEditor,
  513.                     ODFrame* sourceFrame,
  514.                     CSelection* selection);
  515.     
  516.     virtual ~CPasteCommand();
  517.     
  518.     // -- Inherited API --
  519.     virtual void DoCommand(Environment* ev);
  520.     virtual void UndoCommand(Environment* ev);
  521.     virtual void RedoCommand(Environment* ev);
  522.     
  523.     virtual void CaptureCommandState(Environment* ev);
  524.     virtual void Commit(Environment* ev, ODDoneState state);
  525.  
  526.     // -- New API ( Paste Stuff ) --
  527.     
  528.     // Paste methods
  529.     virtual void HandlePaste(Environment* ev);
  530.     void        SelectPastedShapes(Environment* ev);
  531.  
  532. protected:
  533.     CSelection*            fSelection;
  534.     ODFrame*            fSourceFrame;
  535.     ODUpdateID            fUpdateID;
  536.     
  537.     COrderedList*        fSavedShapes;
  538.     COrderedList*        fPublishLinks;
  539.     COrderedList*        fSubscribeLinks;
  540. };
  541.  
  542. //=============================================================================
  543. // CPasteAsCommand
  544. // This class was created to extend the functionality of the past command
  545. // to include forcing a merge or embed based on the result of the paste as
  546. // dialog. This command does not include any support for translation of kinds
  547. // since this part only supports one kind. If any support for translation on
  548. // paste as were to be added, it could be done here as well.
  549. //=============================================================================
  550. class CPasteAsCommand : public CPasteCommand
  551. {
  552. public:
  553.     // -- Init --
  554.     CPasteAsCommand(DrawEditor* theEditor,
  555.                     ODFrame* sourceFrame,
  556.                     CSelection* selection, 
  557.                     ODBoolean embedOrMerge);
  558.     
  559.     virtual ~CPasteAsCommand();
  560.     
  561.     // -- Inherited API --
  562.     virtual void HandlePaste(Environment* ev);
  563.  
  564. private:
  565.     // True for embed, false for merge
  566.     ODBoolean            fDoEmbed;
  567. };
  568.  
  569.  
  570. #endif
  571.  
  572.  
  573.